home *** CD-ROM | disk | FTP | other *** search
- /*
- * Forger
- * An init for forcing AOCE digital signitures to always succeed or fail.
- *
- * Copyright © 1993 by David Shayer. All rights reserved.
- *
- * File: Forger.c
- */
-
-
- /***************************** Includes *******************************/
-
- #include <Traps.h>
-
- #include "Forger.h"
-
-
- /***************************** Routines *******************************/
-
- void main (void)
- {
- Handle Self;
-
- asm
- {
- MOVE.L A0, Self
- }
- Self=RecoverHandle (Self);
- DetachResource (Self);
-
- if (CPUFlag<2) // we use some 68020 or greater addressing modes
- return;
- InstallPatch ();
- }
-
-
- void InstallPatch (void)
- {
- long UnimpAddr, DigSigAddr;
-
- DigSigAddr = NGetTrapAddress (_DigitalSignature, ToolTrap);
-
- UnimpAddr = GetTrapAddress (_Unimplemented);
- if (UnimpAddr==DigSigAddr)
- return;
-
- SetAddr (DigSigAddr);
- NSetTrapAddress ((long)DigitalSignaturePatch, _DigitalSignature, ToolTrap);
- }
-
-
- void SetAddr (long OrigDigSigAddr)
- {
- DataRecPtr DataPtr;
-
- DataPtr=GetDataAddr ();
- DataPtr->TrapAddr=OrigDigSigAddr;
- }
-
-
- DataRecPtr GetDataAddr (void)
- {
- DataRecPtr DataPtr;
-
- asm
- {
- MOVE.L #kControlAddr, D0
- JSR DigitalSignaturePatch
- MOVE.L D0, DataPtr
- }
- return DataPtr;
- }
-
-
- // do a tail patch! naughty naughty!
- void DigitalSignaturePatch (void)
- {
- asm
- {
- ; handle control calls - return addr of storage in D0
- CMP.L #kControlAddr, D0 ; is it our magic selector?
- BNE.S @3 ; if not, skip ahead
- LEA @DSAddr, A0 ; get addr of our data
- MOVE.L A0, D0 ; store addr in return register
- RTS ; return
-
- ; see if forger is on
- @3 TST.W @On ; is forger turned on?
- BNE.S @4 ; if its on, branch to handler
- MOVE.L @DSAddr, -(A7) ; its off, so push addr of _DigitalSignature
- RTS ; jump to _DigitalSignature
-
- ; check for SIGVerify
- @4 CMP.L #kSIGVerify,D0 ; is it SIGVerify?
- BEQ.S @5 ; if so, jump to handler
-
- ; check for SIGShowSigner
- CMP.L #kSIGShowSigner,D0 ; is it SIGShowSigner?
- BEQ.S @10 ; if so, jump to handler
-
- ; not a selector we want
- MOVE.L @DSAddr, -(A7) ; its not, so push addr of _DigitalSignature
- RTS ; jump to _DigitalSignature
-
- ;;; SIGShowSigner handler ;;;
- ; succeed or fail?
- @10 TST.W @Suceed ; test Suceed
- BEQ.S @12 ; if its fail, jump ahead
-
- ; handle SIGShowSigner succeed
- ; make real call, let it go if it succeeds, if it fails, force it to succeed
- MOVE.L A1, -(A7) ; save A1
- LEA @Store, A1 ; load addr of storage
- MOVE.L 4(A7), (A1) ; save real return addr
- LEA @11, A1 ; get our return addr
- MOVE.L A1, 4(A7) ; insert our return addr
- MOVE.L (A7)+, A1 ; restore A1
- MOVE.L @DSAddr, -(A7) ; push addr of _DigitalSignature
- RTS ; call real _DigitalSignature
- @11 TST.W (A7) ; did call succeed?
- BNE.S @13 ; if it succeeded, fall thru and return
- MOVE.L @Store, -(A7) ; get real return addr
- RTS ; return
-
- @13 ; real SIGShowSigner failed, so fake succees
- JSR FakeSuccees ; call routine to fake success
- MOVE.W #0, (A7) ; set noErr return value
- MOVE.L @Store, -(A7) ; get real return addr
- RTS ; return
-
- ; handle SIGVerify fail
- @12 ADDQ.L #8, A7 ; pop params from stack
- MOVE.W #kSigSignError, (A7) ; set error return value
- RTS ; return
-
-
-
-
- ;;; SIGVerify handler ;;;
- ; succeed or fail?
- @5 TST.W @Suceed ; test Suceed
- BEQ.S @7 ; if its fail, jump ahead
-
- ; handle SIGVerify succeed
- MOVE.L A1, -(A7) ; save A1
- LEA @Store, A1 ; load addr of storage
- MOVE.L 4(A7), (A1) ; save real return addr
- LEA @6, A1 ; get our return addr
- MOVE.L A1, 4(A7) ; insert our return addr
- MOVE.L (A7)+, A1 ; restore A1
- MOVE.L @DSAddr, -(A7) ; push addr of _DigitalSignature
- RTS ; call real _DigitalSignature
- @6 MOVE.W #0, (A7) ; insert an noErr
- MOVE.L @Store, -(A7) ; get real return addr
- RTS ; return
-
-
- ; handle SIGVerify fail
- @7 MOVE.L A1, -(A7) ; save A1
- LEA @Store, A1 ; load addr of storage
- MOVE.L 4(A7), (A1) ; save real return addr
- LEA @8, A1 ; get our return addr
- MOVE.L A1, 4(A7) ; insert our return addr
- MOVE.L (A7)+, A1 ; restore A1
- MOVE.L @DSAddr, -(A7) ; push addr of _DigitalSignature
- RTS ; call real _DigitalSignature
- @8 MOVE.W #kSigVerifyError, (A7) ; insert an error
- MOVE.L @Store, -(A7) ; get real return addr
- RTS ; return
-
- ; data storage
- @DSAddr DC.L 0 ; addr of _DigitalSignature trap
- @On DC.W 0 ; 1=forger is on, 0=forger is off
- @Suceed DC.W 1 ; 1=always suceed, 0=always fail
- @Store DC.L 0 ; temp storage
- }
- }
-
-
- // do a wimpy immitation of a successful dialog
- void FakeSuccees (void)
- {
- short RefNum;
-
- RefNum=OpenResFile ("\pForger Data");
- if (RefNum==-1)
- return;
- Alert (128, NULL);
- CloseResFile (RefNum);
- }
-
-
-
-
-
-
-